package com.guigu.www.service.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.www.mapper.CellMapper;
import com.guigu.www.pojo.Cell;
import com.guigu.www.pojo.GatherDetails;
import com.guigu.www.pojo.PayDetails;
import com.guigu.www.service.CellService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.swing.border.Border;
import java.util.List;

@Service
public class CellServiceImpl extends ServiceImpl<CellMapper, Cell> implements CellService {
    //获取map
    @Autowired
    CellMapper cellMapper;
    //查询安全库存待审核的
    @Override
    public PageInfo<Cell> queryByCellByCheckTag(int pageno,int pagesize,Cell cell) {
        cell.setProductName("");
        //获取方法
        PageHelper.startPage(pageno,pagesize);
        //调用方法
        List<Cell> list = cellMapper.queryByCellByCheckTag(cell);
        //创建pageinfo
        PageInfo<Cell>pageInfo=new PageInfo<Cell>(list);
        return pageInfo;
    }
    //复核通过修改状态
    @Override
    public boolean queryByCekkUpdatestatus(Cell cell) {
        //获取方法
        return cellMapper.queryByCekkUpdatestatus(cell)>=1?true:false;
    }
    //查询所以指定安全库存的产品分页
    @Override
    public IPage<Cell> queryallcellshow(int pageno,int pagesize,Cell cell) {
        //获取page
        Page page=new Page(pageno,pagesize);

        //设置条件
        QueryWrapper<Cell> queryWrapper=new QueryWrapper<Cell>();
        //设置值
        if(StringUtils.isNotBlank(cell.getProductName())){
            queryWrapper.like("product_name",cell.getProductName());
        }
        //根据id查询
        if(cell.getId()!=-1){
            queryWrapper.eq("ID",cell.getId());
        }
        //return
        return this.page(page,queryWrapper);
    }
    //查询所有审核通过的产品 变更
    @Override
    public PageInfo<Cell> queryCellByCellId(int pageno, int pagesize, Cell cell) {
        //分页方法
        PageHelper.startPage(pageno,pagesize);
        //调用方法
       List<Cell> list=cellMapper.queryCellByCellId(cell);
       //创建pageinfo
        PageInfo<Cell> pageInfo=new PageInfo<Cell>(list);
        return pageInfo;
    }
    //登记审核成功修改库存信息
    @Override
    public boolean updatewarehousingexaminequeryCellByGathers(List<GatherDetails> gatherDetails) {
        int i=0;
        boolean f=false;
        //设置值
        for (GatherDetails gatherDetail : gatherDetails) {
            System.out.println(gatherDetail);
            //查询当前产品编号
            //创建对象cell
            Cell cell=cellMapper.querywarehousingexaminequeryCellByGathers(gatherDetail.getProductId());
            //设置值
            //当前最大存储数量
            Double num=(Double.parseDouble(cell.getMaxCapacityAmount())-Double.parseDouble(gatherDetail.getGatheredAmount()));
            //当前储存数量
            Double num1=(Double.parseDouble(cell.getAmount())+Double.parseDouble(gatherDetail.getGatheredAmount()));
            cell.setMaxCapacityAmount(num.toString());
            cell.setAmount(num1.toString());
            //调用方法
           i=i+cellMapper.updatewarehousingexaminequeryCellByGathers(cell);
        }
        if(gatherDetails.size()==i){
            f=true;
        }
        return f;
    }

    @Override
    public IPage<Cell> dynamicinventory(int pageno, int pagesize) {
        //创建page
        Page page=new Page(pageno,pagesize);
        //获取设置条件
        QueryWrapper<Cell> queryWrapper=new QueryWrapper<Cell>();
        //设置条件
        queryWrapper.eq("check_tag","C003");
        return this.page(page,queryWrapper);
    }

    //首页echarts报表查询仓库所有数据
    @Override
    public List<Cell> queryCellByDate() {
        return cellMapper.queryCellByDate();
    }

    /*//调用修改库存表的数量
    @Override
    public boolean updateCellByproductId(Cell cell) {
        return cellMapper.updateCellByproductId(cell)>0?true:false;
    }*/
}
